package co.edu.interfaz;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.SwingUtilities;

import co.edu.aplicacion.Cancion;
import co.edu.aplicacion.servicios.def.IReproductor;
import co.edu.aplicacion.servicios.impl.Reproductor;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ReproductorInterfazInicial extends javax.swing.JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3543637369788618823L;
	private JMenuItem helpMenuItem;
	private JMenu jMenu5;
	private JLabel cancion;
	private JSeparator seperador;
	private JLabel reproduciendo;
	private JLabel jLabel2;
	private JLabel jLabel1;
	private JButton jButton1;
	private JLabel Titulo;
	private JMenuItem deleteMenuItem;
	private JSeparator jSeparator1;
	private JMenuItem pasteMenuItem;
	private JMenuItem copyMenuItem;
	private JMenuItem cutMenuItem;
	private JMenu jMenu4;
	private JMenuItem exitMenuItem;
	private JSeparator jSeparator2;
	private JMenuItem closeFileMenuItem;
	private JMenuItem saveAsMenuItem;
	private JMenuItem saveMenuItem;
	private JButton jButton3;
	private JButton jButton2;
	private JMenuItem openFileMenuItem;
	private JMenuItem newFileMenuItem;
	private JMenu jMenu3;
	private JMenuBar jMenuBar1;
	private final IReproductor reproductor=new Reproductor();
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				ReproductorInterfazInicial inst = new ReproductorInterfazInicial();
				inst.setVisible(true);
			}
		});
	}
	
	public ReproductorInterfazInicial() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		try {
			{
				Titulo = new JLabel();
				this.setLayout(null);
				getContentPane().add(Titulo);
				Titulo.setText("Reproductor");
				Titulo.setBounds(343, 0, 115, 26);
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Cargar Canciones");
				jButton1.setBounds(7, 83, 181, 22);
				jButton1.addActionListener(new ActionListener() {
					
					private JScrollPane scrollPane;

					@Override
					public void actionPerformed(ActionEvent e) {
						Date inicio=new Date();
						long inicial=System.currentTimeMillis();
						List<Cancion> canciones= reproductor.buscarCanciones("D:\\LATITUDE\\Music\\CarpetaPersonal");
						long finalt=System.currentTimeMillis();
						System.out.println("Tiempo :"+(finalt-inicial));
						Collections.sort(canciones,new Comparator<Cancion>() {
							@Override
							public int compare(Cancion o1, Cancion o2) {
								String valor1=o1.getNombre()==null?"":o1.getNombre();
								String valor2=o2.getNombre()==null?"":o2.getNombre();
								return valor1.compareTo(valor2);
							}
						});
						Date fin=new Date();
						final TablaCanciones tab= new TablaCanciones();
						for(Cancion cancion:canciones){
							tab.adicionarCanciones(cancion);
						}
						final JTable tablaCanciones = new JTable(tab);
						scrollPane=new JScrollPane(tablaCanciones,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
						scrollPane.setBounds(300, 50, 700, 200);
						jLabel2.setText(canciones.size()+"");
						getContentPane().add(scrollPane);
						repaint();
						fin=new Date();
						System.out.println((fin.getTime()-inicio.getTime()));
						tablaCanciones.addMouseListener(new MouseAdapter() {
							@Override
							public void mouseClicked(MouseEvent e) {
								 int fila = tablaCanciones.rowAtPoint(e.getPoint());
								 Cancion cancion=	tab.obtenerCancion(fila);
								 reproductor.reproducir(cancion);
								 ReproductorInterfazInicial.this.cancion.setText(cancion.getNombre());
							}
						});
					}
				});
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Canciones Encontrada");
				jLabel1.setBounds(12, 158, 171, 15);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setBounds(189, 158, 80, 13);
			}
			{
				reproduciendo = new JLabel();
				getContentPane().add(reproduciendo);
				reproduciendo.setText("Reproduciendo");
				reproduciendo.setBounds(12, 306, 171, 16);
			}
			{
				seperador = new JSeparator();
				getContentPane().add(seperador);
				seperador.setBounds(12, 266, 1059, -38);
			}
			{
				cancion = new JLabel();
				getContentPane().add(cancion);
				cancion.setBounds(12, 347, 100, 30);
				cancion.setBackground(Color.RED);
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("Pausar");
				jButton2.setBounds(429, 346, 55, 23);
				jButton2.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						reproductor.pausar();
					}
				});
			}
			{
				jButton3 = new JButton();
				getContentPane().add(jButton3);
				jButton3.setText("Reproducir");
				jButton3.setBounds(309, 346, 72, 23);
				jButton3.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						
					}
				});
			}
			this.setSize(1005, 454);
			{
				jMenuBar1 = new JMenuBar();
				setJMenuBar(jMenuBar1);
				{
					jMenu3 = new JMenu();
					jMenuBar1.add(jMenu3);
					jMenu3.setText("File");
					{
						newFileMenuItem = new JMenuItem();
						jMenu3.add(newFileMenuItem);
						newFileMenuItem.setText("New");
					}
					{
						openFileMenuItem = new JMenuItem();
						jMenu3.add(openFileMenuItem);
						openFileMenuItem.setText("Open");
					}
					{
						saveMenuItem = new JMenuItem();
						jMenu3.add(saveMenuItem);
						saveMenuItem.setText("Save");
					}
					{
						saveAsMenuItem = new JMenuItem();
						jMenu3.add(saveAsMenuItem);
						saveAsMenuItem.setText("Save As ...");
					}
					{
						closeFileMenuItem = new JMenuItem();
						jMenu3.add(closeFileMenuItem);
						closeFileMenuItem.setText("Close");
					}
					{
						jSeparator2 = new JSeparator();
						jMenu3.add(jSeparator2);
					}
					{
						exitMenuItem = new JMenuItem();
						jMenu3.add(exitMenuItem);
						exitMenuItem.setText("Exit");
					}
				}
				{
					jMenu4 = new JMenu();
					jMenuBar1.add(jMenu4);
					jMenu4.setText("Edit");
					{
						cutMenuItem = new JMenuItem();
						jMenu4.add(cutMenuItem);
						cutMenuItem.setText("Cut");
					}
					{
						copyMenuItem = new JMenuItem();
						jMenu4.add(copyMenuItem);
						copyMenuItem.setText("Copy");
					}
					{
						pasteMenuItem = new JMenuItem();
						jMenu4.add(pasteMenuItem);
						pasteMenuItem.setText("Paste");
					}
					{
						jSeparator1 = new JSeparator();
						jMenu4.add(jSeparator1);
					}
					{
						deleteMenuItem = new JMenuItem();
						jMenu4.add(deleteMenuItem);
						deleteMenuItem.setText("Delete");
					}
				}
				{
					jMenu5 = new JMenu();
					jMenuBar1.add(jMenu5);
					jMenu5.setText("Help");
					{
						helpMenuItem = new JMenuItem();
						jMenu5.add(helpMenuItem);
						helpMenuItem.setText("Help");
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	

}
